<template>
	<view class="container" style="position: relative;">
		<swiper autoplay="true" indicator-dots="true" circular="true" style="height: 750upx;">
			<swiper-item v-for="(img,key) in data.goods_images" :key="key" style="height: 750upx;width: 100%;">
				<image :src="img" style="height: 750upx;width: 100%;" mode="widthFix" />
			</swiper-item>
		</swiper>
		
		<view class="introduce-section">
			<view v-if="sure == 0" style="padding: 20upx 30upx;">
				<view class="price-box">
					<text class="price-tip" style="color: #000000;">¥</text>
					<text class="price" style="font-size: 36upx;font-weight: 555;color: #000000;">{{data.level_price}}</text>
					<text class="m-price">¥{{data.cost_price}}</text>
				</view>
				<view style="position: relative;">
					<text class="title" style="font-size: 36upx;font-weight: 555;">{{data.goods_name}}</text>
					<text class="title" style="position: absolute;right: 20upx;color: #888888;">{{data.format}}</text>
				</view>
				<view>
					<text class="title" style="font-size: 28upx;color: #cccccc;">{{data.goods_desc}}</text>
				</view>
			</view>
			<view v-if="sure == 1">
				<view class="price-box" style="position: relative;display: flex;background-color: #AF2839;color: #fff;width: 750upx;height: 100upx;line-height: 100upx;">
					<text class="price-tip" style="margin-left: 30upx;">¥</text>
					<text class="price" style="font-size: 46upx;color: #fff;">{{data.cost_price}}</text>
					<!-- <text class="m-price" style="font-size: 30upx;color: #fff;">原价:{{data.}}</text> -->
					<text class="price"  style="margin-left: 20upx;">{{data.number}}人团</text>
					<uni-countdown :day="day" :hour="hr" :minute="min" :second="sec" style=" position: absolute;top: 0upx;right: 0upx;background: transpant;background:transparent;margin-top: 25upx;"></uni-countdown>
				</view>
				<view style="display: flex;flex-wrap: wrap;height: 150upx;color: #000000;">
					<view style="width: 750upx;margin-left: 50upx;margin-top: 30upx;">
						<text class="title" style="font-size: 38upx;font-weight: bold;">[拼团]</text>
						<text class="title" style="font-size: 38upx;padding-left: 20upx;">{{data.goods_name}}</text>
					</view>
					<view style="width: 750upx;margin-left: 50upx;">
						<text class="title" style="font-size: 30upx;color: #575556;">{{data.goods_short}}</text>
					</view>
				</view>
			</view>
		</view>
		

		<!-- 右侧固定分享按钮 -->
		<view style="
		margin: 0;padding: 0;border: 1px solid transparent;outline: none;
		position: fixed;bottom: 400upx;right: 10upx;width: 100upx;height: 150upx;z-index: 2;border: 1upx solid #fff;background-color: #fff;box-shadow: 10upx -5upx 10upx #CCCCCC;border-radius: 5upx;"
		@click="share_show"
		v-if="sure==0"
			>
			<view>
				<image src="../../static/share.png" style="width: 60upx;height: 60upx;margin: 20upx 20upx 0;"></image>
				<view style="height: 40upx;line-height: 40upx;font-size: 25upx;text-align: center;border-top: 1upx solid #cccccc;margin: 10upx 10upx 0;color: #000;">分享</view>
			</view>
		</view>
		<!-- <view v-if="sure == 0">
			<view class="c-list">
				<view class="c-row b-b" @click="toggleSpec">
					<text class="tit" style="flex: 8;">购买数量:</text>
					<text style="flex: 1;text-align: right;">{{numberValue}}</text>
					<view class="con">
						<text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">
							{{sItem.name}}
						</text>
					</view>
					<text class="yticon icon-you"></text>
				</view>
			</view>
		</view> -->
		
		<view class="detail-desc" v-if="sure == 0">
			<view class="d-header">
				<text>图文详情</text>
			</view>
			<image :src="data.goods_detail" style="width: 100%;" mode="widthFix"></image>
		</view>
		
		<view v-if="sure == 1" style="text-align: center;background-color: #fff;">
			
			<view style="border-top: 1upx solid #ccc;border-bottom: 1upx solid #ccc;height: 400upx;padding-top: 100upx;" v-if="userGroup.length==0">
				<view>
					<image :src="item.real_head_img" v-for="(item,index) in userInfo" :key="index" mode="" style="width: 80upx;height: 80upx;border-radius: 40upx;margin-left: -15upx;"></image>
				</view>
				<view>
					开团后邀请好友组团
				</view>
				<view style="position: relative;">
					<progress style="width: 60%;margin-left: 20%;margin-top: 30upx;z-index: -999;" :percent="percent1" activeColor='#f00' stroke-width='1' />
					<view style="color: #f00;position: absolute;top: -18upx;left: 85upx;">
						<view>
							<image style="width: 40upx;height: 40upx;" src="../../static/progress2.png" mode=""></image>
						</view>
						发起拼团
					</view>
					<view style="color: #f00;position: absolute;top: -18upx;left: 300upx;">
						<view>
							<image v-if="percent1 >= 50" style="width: 40upx;height: 40upx;" src="../../static/progress2.png" mode=""></image>
							<image v-if="percent1 < 50 " style="width: 40upx;height: 40upx;" src="../../static/progress1.png" mode=""></image>
						</view>
						<view :style="{color: color1}">
							邀请好友参团
						</view>
					</view>
					<view style="color: #f00;position: absolute;top: -18upx;left: 560upx;">
						<view>
							<image v-if="percent1 !== 100" style="width: 40upx;height: 40upx;" src="../../static/progress1.png" mode=""></image>
							<image v-if="percent1 == 100" style="width: 40upx;height: 40upx;" src="../../static/progress2.png" mode=""></image>
						</view>
						<view :style="{color: color2}">
							拼团成功
						</view>
					</view>
				</view>
			</view>
			
			<view v-for="(group,inx) in userGroup" :key="inx" style="border-bottom: 1upx solid #ccc;height: 400upx;padding-top: 100upx;" v-if="userGroup.length>0">
			
				<view>
					<view>
						<image :src="item.real_head_img" v-for="(item,index) in group.userInfo" :key="index" mode="" style="width: 80upx;height: 80upx;border-radius: 40upx;margin-left: -15upx;"></image>
					</view>
					<view>
						开团后邀请好友组团
					</view>
					<view style="position: relative;" >
						<progress style="width: 60%;margin-left: 20%;margin-top: 30upx;z-index: -999;" :percent="group.groupInfo.is_join" activeColor='#f00' stroke-width='1' />
						<view style="color: #f00;position: absolute;top: -18upx;left: 85upx;">
							<view>
								<image style="width: 40upx;height: 40upx;" src="../../static/progress2.png" mode=""></image>
							</view>
							发起拼团
						</view>
						<view style="color: #f00;position: absolute;top: -18upx;left: 300upx;">
							<view>
								<image v-if="group.groupInfo.is_join >= 50" style="width: 40upx;height: 40upx;" src="../../static/progress2.png" mode=""></image>
								<image v-if="group.groupInfo.is_join < 50 " style="width: 40upx;height: 40upx;" src="../../static/progress1.png" mode=""></image>
							</view>
							<view :style="{color: group.groupInfo.is_join >= 50?'#f00':'#919191'}">
								邀请好友参团
							</view>
						</view>
						<view style="color: #f00;position: absolute;top: -18upx;left: 560upx;">
							<view>
								<image v-if="group.groupInfo.is_join !== 100" style="width: 40upx;height: 40upx;" src="../../static/progress1.png" mode=""></image>
								<image v-if="group.groupInfo.is_join == 100" style="width: 40upx;height: 40upx;" src="../../static/progress2.png" mode=""></image>
							</view>
							<view :style="{color: group.groupInfo.is_join == 100?'#f00':'#919191'}">
								拼团成功
							</view>
						</view>
					</view>
				</view>
				
			</view>
			<view style="height: 500upx;padding: 50upx 20upx;color: #626262;">
					<view style="font-weight: bold;font-size: 38upx;">
						普通拼团规则
					</view>
					<view style="text-align: left;">
						<view style="font-weight: bold;border-left: 10upx solid #f00;padding-left: 20upx;margin: 30upx 0upx;">
							团长
						</view>
						<view>
							团长是该团第一位购买并支付成功的人;
						</view>
						<view style="font-weight: bold;border-left: 10upx solid #f00;padding-left: 20upx;margin: 30upx 0upx;">
							开团
						</view>
						<view>
							团长发起拼团,购买商品完成支付后,团即可开启;
						</view>
					</view>
			</view>
		</view>
		<!-- 普通详情页  底部操作菜单-->
		<view class="page-bottom" v-if="sure != 1">
			<navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn">
				<text class="yticon icon-xiatubiao--copy"></text>
				<text>首页</text>
			</navigator>
			<navigator url="/pages/cart/cart" open-type="switchTab" class="p-b-btn" style="position: relative;" v-if="sure == 0">
				<text class="yticon icon-gouwuche"></text> 
				<view style="position: absolute;right: 10upx;top: -25upx;">
					<uni-badge :text="shopcarnum" type="error"></uni-badge>
				</view>
				<text>购物车</text>
			</navigator>
			<view class="action-btn-group" style="width: 500upx;">
				<button type="primary" class=" action-btn no-border buy-now-btn"  @click="jumpto"  >立即购买</button>
				<!-- @click="buy"  -->
				<button type="primary" class=" action-btn no-border add-cart-btn" @click="addToShopcar" v-if="sure == 0">加入购物车</button>
			</view>
		</view>
		<!-- 拼团页底部 -->
		<view class="page-bottom" v-if="sure == 1">
			<navigator url="/pages/index/index" open-type="switchTab" class="p-b-btn" style="margin-left: 50upx;">
				<text class="yticon icon-xiatubiao--copy"></text>
				<text>首页</text>
			</navigator>
			<view class="p-b-btn" style="position: relative;" v-if="sure == 0" @click="jumpto">
				<text class="yticon icon-gouwuche"></text> <view style="position: absolute;right: 10upx;top: -25upx;">
				<uni-badge :text="shopcarnum" type="error"></uni-badge></view>
				<text>购物车</text>
			</view>
			<view class="action-btn-group" style="width: 500upx;">
				<button type="primary" class=" action-btn no-border buy-now-btn" @click="buy">立即购买</button>
				<button type="primary" class=" action-btn no-border add-cart-btn" @click="addToShopcar" v-if="sure == 0">加入购物车</button>
			</view>
		</view>
		
		<!-- 规格-模态层弹窗 -->
		<view 
			class="popup spec" 
			:class="specClass"
			@touchmove.stop.prevent="stopPrevent"
			@click="toggleSpec"
		>
			<!-- 遮罩层 -->
			<view class="mask"></view>
			<view class="layer attr-content" @click.stop="stopPrevent">
				<view class="a-t">
					<image :src="data.goods_thumb_image"></image>
					<view class="right">
						<text class="price">单价:￥{{data.level_price}}</text>
						<!-- <text class="stock">库存：188件</text> -->
						<!-- <view class="selected">
							已选：
							<text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">
								{{sItem.name}}
							</text>
						</view> -->
					</view>
				</view>
				<view style="height: 150upx;">
					<view style="margin-top: 100upx;">
						<uni-number-box :value="numberValue" @change="change" />
					</view>
				</view>
				<button class="btn" @click="toggleSpec" style="background-color: #000000;">完成</button>
			</view>
		</view>
		
		<view class="fade_in_out" :class="fade"  @click="hide">
			<view style="width:100%;">
				<image :src="share_img" mode="widthFix" style="width: 550upx;display: inline-block;margin-top: 110upx;height: 748upx;"></image>
			</view>
			<view style="width:100%;margin-top: 40upx;text-align: center;">
				<button
					style="
					margin: 0;padding: 0;border: 1px solid transparent;outline: none;
					width: 300upx;height: 90upx;border-radius: 40upx;background-color: #D41C52;line-height: 90upx;color: #fff;display: inline-block;"
					@click.stop.prevent="saveImgToLocal"
				>保存海报</button>
			</view>
			<view style="width:100%;margin-top: 40upx;text-align: center;height: 90upx;line-height: 90upx;color: #fff;" @click="openSetting">
				<!-- <button
					style="
					margin: 0;padding: 0;border: 1px solid transparent;outline: none;background: transprant;
					width: 300upx;height: 90upx;line-height: 90upx;color: #fff;display: inline-block;"
					open-type="openSetting" bindopensetting="callback"
				></button> -->
				图片保存不了?来这里设置
			</view>
		</view>
		
		<!-- 分享 -->
		<!-- <share 
			ref="share" 
			:contentHeight="580"
			:shareList="shareList"
			:goods_id="goods_id"
		></share> -->
	</view>
</template>

<script>
	import uniCountdown from '@/components/uni-countdown/uni-countdown.vue'
	import uniBadge from "@/components/uni-badge/uni-badge.vue"
	// import share from '@/components/share';
	import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue'
	// import uniSection from '@/components/uni-section/uni-section.vue'
	export default{
		onShareAppMessage(res) {
			if (res.from === 'button') {// 来自页面内分享按钮
				
			}
			if (this.sure == 0) {
				return {
					// imageUrl: '../../static/image/sw8.png',
					title: '生物伞 美购商城',
					path: '/pages/product/product?goodsid=' + this.goods_id + '&select_userid=' + this.select_userid  + '&sure=0'
				}
			}
			if (this.sure == 1) {
				return {
					// imageUrl: '../../static/image/sw8.png',
					title: '生物伞 美购商城',
					path: '/pages/product/product?goodsid=' + this.goods_id + '&select_userid=' + this.select_userid  + '&sure=1'
				}
			}
			
		},
		components: {
			// share,
			uniNumberBox,
			uniBadge,
			uniCountdown
		},
		data() {
			return {
				user_id:'',
				level_id: 1,
				res:[],
				percent1: 0, // 拼团进度条
				shopcarnum: 1,  // 购物车商品数量
				numberValue: 1, // 购买数量
				goods_id:'',  // 发起拼团的id
				group_id: 0,  // 分享进入拼团的拼团id
				data: {},
				specClass: 'none',
				specSelected:[],
				favorite: true,
				shareList: [
					{
						type: 1,
						icon: '/static/temp/share_wechat.png',
						text: '微信好友'
					},
					// {
					// 	type: 2,
					// 	icon: '/static/temp/share_moment.png',
					// 	text: '朋友圈'
					// },
				],
				goods_images: [],
				// 选择规格
				specChildList: [
					{id: 1,pid: 1,name: 'XS',},
					{id: 2,pid: 1,name: 'S',},
					{id: 3,pid: 1,name: 'M',},
					{id: 4,pid: 1,name: 'L',},
				],
				sure: 0,
				day: 0,
				hr: 0,
				min: 0,
				sec: 0,
				// groupInfo:{},
				userInfo:[],
				select_userid: 0,
				color1:'#919191',
				color2:'#919191',
				share_img: '',
				fade:'none',
				index: 1,
				userGroup:[],
			};
		},
		onLoad(e){
			// if (e.scene) { // 通过小程序码分享进来之后跳转的页面,多参数
			// 	const scene = decodeURIComponent(e.scene)
			// 	let obj = {};
			// 	let arr2 = scene.split("&");
			// 	for(let i=0 ; i < arr2.length; i++){
			// 		let res = arr2[i].split("=");
			// 		obj[res[0]] = res[1];
			// 	}
				
			// 	if (obj.old_openid) {
			// 		uni.setStorage({
			// 			key: 'old_openid',
			// 			data: obj.old_openid
			// 		});
			// 	}
				
			// 	if (obj.goodsid && obj.select_user_id) {
			// 		uni.reLaunch({
			// 			url: '/pages/product/product?goodsid=' + obj.goodsid + '&select_user_id=' + obj.select_user_id,
			// 		})
			// 	} else {
			// 		uni.reLaunch({
			// 			url: '/pages/product/product?goodsid=' + obj.goodsid,
			// 		})
			// 	}
				
			// }
			
			let inte = e
			let o = this
			if(e.sure == 1) {
				this.sure = e.sure
				uni.setNavigationBarTitle({
				    title: '拼团详情'
				});
			}
			uni.getStorage({
				key: 'level_id',
				success: (res) => {
					this.level_id = res.data
				},
				fail: () => {}
			});
			
			// if (e.group_id) {
			// 	this.group_id = e.group_id
			// 	this.setAjax_group()
			// }
			// 文章页面分享过来的id
			if (e.select_userid) {
				this.select_userid = e.select_userid
			}
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
				 this.user_id = res.data
				 if (inte.goodsid) {
				 	this.goods_id = inte.goodsid
				 	this.setAjax()
				 }
				 if (inte.group_id) {
				 	this.group_id = inte.group_id
				 	this.setAjax_group()
				 }
				},
				fail: () => {
					// 未获取到user_id
					// uni.navigateTo({
					// 	url:'../login/login'
					// })
					this.user_id = 0
					if (inte.goodsid) {
						this.goods_id = inte.goodsid
						this.setAjax()
					}
					if (inte.group_id) {
						this.group_id = inte.group_id
						this.setAjax_group()
					}
				}
			});
			// uni.getSetting({
			//    success(res) {
			// 			if (res.authSetting['scope.writePhotosAlbum'] != undefined && res.authSetting['scope.writePhotosAlbum'] == false) {
			// 				uni.hideLoading();
			// 				o.save = false
			// 			} else {
			// 				o.save = true
			// 		 }
			//    }
			// })
			// setTimeout(()=> {
			// 	o.share_show1()
			// }, 3000);
		},
		// onPullDownRefresh() {
		// 	let o = this
		// 	setTimeout(function () {
		// 		o.setajax();
		// 		uni.stopPullDownRefresh();
		// 	}, 1000);
		// },
		methods:{
			jumpto() {
				// if(this.select_userid!=0) {
				// 	uni.navigateTo({
				// 		url: '/pages/order/createOrder?orderid=' + this.goods_id + '&number=' + this.numberValue + '&sure=' + this.sure + '&level_id=' + this.level_id + '&select_userid=' + this.select_userid
				// 	})
				// 	return
				// }
				uni.reLaunch({
					url: '/pages/cart/cart'
				})
			},
			setAjax_group() {
				// 根据开团id获取拼团
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/AssembleGroup/detail',
					method: 'POST',
					header:{ 'Content-Type':'application/x-www-form-urlencoded'},
					data:{
						group_id: this.group_id,
						session_id: uni.getStorageSync("sessionid")
					},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						this.is_join = res.data.data.is_join
						if(this.is_join == 2) {
							this.percent1 = 50
							this.color1 = '#ff0000'
						}
						if (this.is_join == 3) {
							this.color1 = '#ff0000'
							this.color2 = '#ff0000'
							this.percent1 = 100
						}
						this.groupInfo = res.data.data.groupInfo
						if(res.data.data.userInfo) {
							this.userInfo = res.data.data.userInfo
						}
						// this.percent1 = this.groupInfo.share_percent
						
						this.goods_id = res.data.data.groupInfo.assemble_id
						this.setAjax()
					},
					fail: () => {},
					complete: () => {}
				});
			},
			setAjax(){
				this.index = 1
				var o = this
				if(this.sure == 0) {
					uni.request({
						url: 'https://cx.mingmeijt.com/Api/Goods/goodsDetail',
						method: 'POST',
						data:{
							user_id: this.user_id,
							goods_id: this.goods_id,
							session_id: uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: (res) => {
							if(res.data.code == 999){
								uni.navigateTo({
									url:'/pages/999/999'
								})
							};
							this.data = res.data.data.data
							this.shopcarnum = res.data.data.goodsCartCount
							this.data.goods_thumb_image = 'https://cx.mingmeijt.com' + this.data.goods_thumb_image
							this.data.goods_thumb = 'https://cx.mingmeijt.com' + this.data.goods_thumb
							this.data.goods_detail = 'https://cx.mingmeijt.com' + this.data.goods_detail
							for(let i=0; i<o.data.goods_images.length; i++) {
								o.data.goods_images[i] = 'https://cx.mingmeijt.com' + o.data.goods_images[i]
							}
						}
					});
				}
				if(this.sure == 1) {
					// 发起拼团活动详情
					if ( this.goods_id != '' && this.goods_id != undefined ) {
						uni.request({
							url: 'https://cx.mingmeijt.com/Api/Assemble/detail',
							method: 'POST',
							header:{ 'Content-Type':'application/x-www-form-urlencoded'},
							data:{
								id: this.goods_id,
								session_id: uni.getStorageSync("sessionid")
							},
							success: res => {
								this.data = res.data.data
								o.data.goods_images = JSON.parse(o.data.goods_images)
								this.day = res.data.data.second.day
								this.hr = res.data.data.second.hr
								this.min = res.data.data.second.min
								this.sec = res.data.data.second.sec
								for(let i = 0; i < o.data.goods_images.length; i++) {
									o.data.goods_images[i] = 'https://cx.mingmeijt.com' + o.data.goods_images[i]
								}
								if(res.data.userGroup.length>0) {
									this.userGroup = res.data.userGroup
								}
							},
							fail: () => {},
							complete: () => {}
						});
					}
					
				}
				
			},
			// 加载图片,请求拦截
			share_show () {
				if ( this.user_id == '' || this.user_id ==undefined ) {
					uni.reLaunch({
						url: '../login/login'
					})
					return
				}
				this.index++
				if (this.index == 2) {
					uni.showLoading({
						title:"加载中..."
					})
				}
				let o = this
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/QShare/shareGoods',
					method: 'POST',
					data:{
						goods_id: o.goods_id,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: (res) => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if (res.data.code == 500) {
							uni.navigateTo({
								url:'../login/login'
							})
						}
						if (res.data.code == 200) {
							o.share_img = 'https://cx.mingmeijt.com' + res.data.data
						}
						if (this.index == 2) {
							uni.hideLoading()
						}
					}
				});
				setTimeout(()=> {
					o.fade = 'block'
				}, 10);
				
			},
			share_show1 () {
				let o = this
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/QShare/shareGoods',
					method: 'POST',
					data:{
						goods_id: this.goods_id,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: (res) => {
						if (res.data.code == 200) {
							this.share_img = 'https://cx.mingmeijt.com' + res.data.data
						}
					}
				});
			},
			hide () {
				this.fade = 'none'
			},
			openSetting () {
				uni.openSetting()
			},
			saveImgToLocal(){
				let o = this
				uni.downloadFile({
						url: this.share_img,//图片地址
						success: (res) =>{
							console.log(res)
							var imgpath = res.tempFilePath;
							if (res.statusCode === 200){
								uni.saveImageToPhotosAlbum({
									filePath: imgpath,
									success: function(res) {
										uni.hideLoading();
										uni.showToast({
											title: '保存成功！'
										})
									},
									fail: function(res) {
										uni.hideLoading();
										uni.showToast({
											title: '保存失败！',
											icon: 'none'
										})
									}
								})
							}
								// if (res.statusCode === 200){
								// 		uni.saveImageToPhotosAlbum({
								// 				filePath: res.tempFilePath,
								// 				success: function() {
								// 						uni.showToast({
								// 								title: "保存成功",
								// 								icon: "none"
								// 						});
								// 				},
								// 				fail: function() {
								// 						uni.showToast({
								// 								title: "保存失败",
								// 								icon: "none"
								// 						});
								// 				}
								// 		});
								// } 
								setTimeout(function() {
									o.hide()
								}, 10);
						}
				})
			},
			//规格弹窗开关
			toggleSpec() {
				if(this.specClass === 'show'){
					this.specClass = 'hide';
					setTimeout(() => {
						this.specClass = 'none';
					}, 250);
				}else if(this.specClass === 'none'){
					this.specClass = 'show';
				}
			},
			//选择规格
			selectSpec(index, pid){
				let list = this.specChildList;
				list.forEach(item=>{
					if(item.pid === pid){
						this.$set(item, 'selected', false);
					}
				})

				this.$set(list[index], 'selected', true);
				//存储已选择
				/**
				 * 修复选择规格存储错误
				 * 将这几行代码替换即可
				 * 选择的规格存放在specSelected中
				 */
				this.specSelected = []; 
				list.forEach(item=>{ 
					if(item.selected === true){ 
						this.specSelected.push(item); 
					} 
				})
				
			},
			// 加入购物车
			addToShopcar() {
				if (this.numberValue == 0) {
					uni.showToast({
						title: '请选择购买类型,选择数量',
						icon: 'none'
					})
					return
				}
				var o = this
				uni.request({
				    url: 'https://cx.mingmeijt.com/Api/GoodsCart/addCart',
						method: 'POST',
						data:{
							'user_id': this.user_id,
							'goods_id': this.goods_id,
							'number': this.numberValue,
							'session_id': uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
				    success: (res) => {
							if(res.data.code == 200) {
								this.setAjax()
								setTimeout(function() {
									uni.showToast({
										title: '添加购物车成功',
										icon:'none'
									})
								}, 1300);
							}
							if(res.data.code != 200) {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
							}
						}
				});
			},
			change(value) {
				this.numberValue = value
			},
			//分享
			share(){
				this.$refs.share.toggleMask();	
			},
			//收藏
			// toFavorite(){
			// 	this.favorite = !this.favorite;
			// },
			buy(){
				if (this.select_userid!=0) {
					uni.navigateTo({
						url: '/pages/order/createOrder?orderid=' + this.goods_id + '&number=' + this.numberValue + '&sure=' + this.sure + '&level_id=' + this.level_id + '&select_userid=' + this.select_userid
					})
				} else {
					// 拼团购买
					if (this.group_id!= 0) {
						uni.navigateTo({
							url: '/pages/order/createOrder?orderid=' + this.goods_id + '&number=' + this.numberValue + '&sure=' + this.sure + '&level_id=' + this.level_id +'&group_id=' + this.group_id
						})
					} else {
						uni.navigateTo({
							url: '/pages/order/createOrder?orderid=' + this.goods_id + '&number=' + this.numberValue + '&sure=' + this.sure + '&level_id=' + this.level_id
						})
					}
				}
			},
			stopPrevent(){}
		},

	}
</script>

<style lang='scss'>
	page{
		background: $page-color-base;
		padding-bottom: 160upx;
	}
	.fade_in_out {
		position: fixed;top: 0;right: 0;bottom: 0;left: 0;background-color: rgba( 0, 0, 0, 0.3);z-index: 99;text-align: center;
		
		&.block {
			display: block;
			animation: showPopup 0.6s linear both;
		}
		&.none {
			display: none;
			animation: hidePopup 0.6s linear both;
		}
	}
	
	.icon-you{
		font-size: $font-base + 2upx;
		color: #888;
	}
	.carousel {
		height: 722upx;
		position:relative;
		swiper{
			height: 100%;
		}
		.image-wrapper{
			width: 100%;
			height: 100%;
		}
		.swiper-item {
			display: flex;
			justify-content: center;
			align-content: center;
			height: 750upx;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
		
	}
	
	/* 标题简介 */
	.introduce-section{
		background: #fff;
		/* padding: 20upx 30upx; */
		
		.title{
			font-size: 32upx;
			color: $font-color-dark;
			height: 50upx;
			line-height: 50upx;
		}
		.price-box{
			display:flex;
			align-items:baseline;
			height: 64upx;
			/* padding: 10upx 0; */
			font-size: 26upx;
			color:$uni-color-primary;
		}
		.price{
			font-size: $font-lg + 2upx;
		}
		.m-price{
			margin:0 12upx;
			color: $font-color-light;
			text-decoration: line-through;
		}
		.coupon-tip{
			align-items: center;
			padding: 4upx 10upx;
			background: $uni-color-primary;
			font-size: $font-sm;
			color: #fff;
			border-radius: 6upx;
			line-height: 1;
			transform: translateY(-4upx); 
		}
		.bot-row{
			display:flex;
			align-items:center;
			height: 50upx;
			font-size: $font-sm;
			color: $font-color-light;
			text{
				flex: 1;
			}
		}
	}
	/* 分享 */
	.share-section{
		display:flex;
		align-items:center;
		color: $font-color-base;
		background: linear-gradient(left, #fdf5f6, #fbebf6);
		padding: 12upx 30upx;
		.share-icon{
			display:flex;
			align-items:center;
			width: 70upx;
			height: 30upx;
			line-height: 1;
			border: 1px solid $uni-color-primary;
			border-radius: 4upx;
			position:relative;
			overflow: hidden;
			font-size: 22upx;
			color: $uni-color-primary;
			&:after{
				content: '';
				width: 50upx;
				height: 50upx;
				border-radius: 50%;
				left: -20upx;
				top: -12upx;
				position:absolute;
				background: $uni-color-primary;
			}
		}
		.icon-xingxing{
			position:relative;
			z-index: 1;
			font-size: 24upx;
			margin-left: 2upx;
			margin-right: 10upx;
			color: #fff;
			line-height: 1;
		}
		.tit{
			font-size: $font-base;
			margin-left:10upx;
		}
		.icon-bangzhu1{
			padding: 10upx;
			font-size: 30upx;
			line-height: 1;
		}
		.share-btn{
			flex: 1;
			text-align:right;
			font-size: $font-sm;
			color: $uni-color-primary;
		}
		.icon-you{
			font-size: $font-sm;
			margin-left: 4upx;
			color: $uni-color-primary;
		}
	}
	
	.c-list{
		font-size: $font-sm + 2upx;
		color: $font-color-base;
		background: #fff;
		.c-row{
			display:flex;
			align-items:center;
			padding: 20upx 30upx;
			position:relative;
		}
		.tit{
			width: 140upx;
		}
		.con{
			flex: 1;
			color: $font-color-dark;
			.selected-text{
				margin-right: 10upx;
			}
		}
		.bz-list{
			height: 40upx;
			font-size: $font-sm+2upx;
			color: $font-color-dark;
			text{
				display: inline-block;
				margin-right: 30upx;
			}
		}
		.con-list{
			flex: 1;
			display:flex;
			flex-direction: column;
			color: $font-color-dark;
			line-height: 40upx;
		}
		.red{
			color: $uni-color-primary;
		}
	}
	
	/* 评价 */
	.eva-section{
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		margin-top: 16upx;
		.e-header{
			display: flex;
			align-items: center;
			height: 70upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;
			.tit{
				font-size: $font-base + 2upx;
				color: $font-color-dark;
				margin-right: 4upx;
			}
			.tip{
				flex: 1;
				text-align: right;
			}
			.icon-you{
				margin-left: 10upx;
			}
		}
	}
	.eva-box{
		display: flex;
		padding: 20upx 0;
		.portrait{
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			border-radius: 100px;
		}
		.right{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: $font-base;
			color: $font-color-base;
			padding-left: 26upx;
			.con{
				font-size: $font-base;
				color: $font-color-dark;
				padding: 20upx 0;
			}
			.bot{
				display: flex;
				justify-content: space-between;
				font-size: $font-sm;
				color:$font-color-light;
			}
		}
	}
	/*  详情 */
	.detail-desc{
		background: #fff;
		margin-top: 16upx;
		.d-header{
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80upx;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			position: relative;
				
			text{
				padding: 0 20upx;
				background: #fff;
				position: relative;
				z-index: 1;
			}
			&:after{
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translateX(-50%);
				width: 300upx;
				height: 0;
				content: '';
				border-bottom: 1px solid #ccc; 
			}
		}
	}
	
	/* 规格选择弹窗 */
	.attr-content{
		padding: 10upx 30upx;
		.a-t{
			display: flex;
			image{
				width: 170upx;
				height: 170upx;
				flex-shrink: 0;
				margin-top: -40upx;
				border-radius: 8upx;;
			}
			.right{
				display: flex;
				flex-direction: column;
				padding-left: 24upx;
				font-size: $font-sm + 2upx;
				color: $font-color-base;
				line-height: 42upx;
				.price{
					font-size: $font-lg;
					color: $uni-color-primary;
					margin-bottom: 10upx;
				}
				.selected-text{
					margin-right: 10upx;
				}
			}
		}
		.attr-list{
			display: flex;
			flex-direction: column;
			font-size: $font-base + 2upx;
			color: $font-color-base;
			padding-top: 30upx;
			padding-left: 10upx;
		}
		.item-list{
			padding: 20upx 0 0;
			display: flex;
			flex-wrap: wrap;
			text{
				display: flex;
				align-items: center;
				justify-content: center;
				background: #eee;
				margin-right: 20upx;
				margin-bottom: 20upx;
				border-radius: 100upx;
				min-width: 60upx;
				height: 60upx;
				padding: 0 20upx;
				font-size: $font-base;
				color: $font-color-dark;
			}
			.selected{
				background: #fbebee;
				color: $uni-color-primary;
			}
		}
	}
	
	/*  弹出层 */
	.popup {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 99;
		
		&.show {
			display: block;
			.mask{
				animation: showPopup 0.2s linear both;
			}
			.layer {
				animation: showLayer 0.2s linear both;
			}
		}
		&.hide {
			.mask{
				animation: hidePopup 0.2s linear both;
			}
			.layer {
				animation: hideLayer 0.2s linear both;
			}
		}
		&.none {
			display: none;
		}
		.mask{
			position: fixed;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: 1;
			background-color: rgba(0, 0, 0, 0.4);
		}
		.layer {
			position: fixed;
			z-index: 99;
			bottom: 0;
			width: 100%;
			min-height: 40vh;
			border-radius: 10upx 10upx 0 0;
			background-color: #fff;
			.btn{
				height: 66upx;
				line-height: 66upx;
				border-radius: 100upx;
				background: $uni-color-primary;
				font-size: $font-base + 2upx;
				color: #fff;
				margin: 30upx auto 20upx;
			}
		}
		@keyframes showPopup {
			0% {
				opacity: 0;
			}
			100% {
				opacity: 1;
			}
		}
		@keyframes hidePopup {
			0% {
				opacity: 1;
			}
			100% {
				opacity: 0;
			}
		}
		@keyframes showLayer {
			0% {
				transform: translateY(120%);
			}
			100% {
				transform: translateY(0%);
			}
		}
		@keyframes hideLayer {
			0% {
				transform: translateY(0);
			}
			100% {
				transform: translateY(120%);
			}
		}
	}
	
	/* 底部操作菜单 */
	.page-bottom{
		position:fixed;
		/* left: 30upx; */
		bottom:0upx;
		z-index: 95;
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 750upx;
		height: 120upx;
		background-color: #fff;
		/* background: rgba(255,255,255,.9); */
		/* box-shadow: 0 0 20upx 0 rgba(0,0,0,.5); */
		/* border-radius: 16upx; */
		
		.p-b-btn{
			display:flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: $font-sm;
			color: $font-color-base;
			width: 96upx;
			height: 80upx;
			.yticon{
				font-size: 40upx;
				line-height: 48upx;
				color: $font-color-light;
			}
			&.active, &.active .yticon{
				color: $uni-color-primary;
			}
			.icon-fenxiang2{
				font-size: 42upx;
				transform: translateY(-2upx);
			}
			.icon-shoucang{
				font-size: 46upx;
			}
		}
		.action-btn-group{
			display: flex;
			height: 120upx;
			width: 250upx;
			/* border-radius: 100px; */
			overflow: hidden;
			box-shadow: 0 20upx 40upx -16upx #fa436a;
			box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
			background: #AF2839;
			margin-left: 20upx;
			position:relative;
			&:after{
				content: '';
				position:absolute;
				top: 50%;
				right: 50%;
				transform: translateY(-50%);
				height: 28upx;
				width: 0;
				border-right: 1px solid rgba(255,255,255,.5);
			}
			.action-btn{
				display:flex;
				align-items: center;
				justify-content: center;
				width: 180upx;
				height: 100%;
				font-size: $font-base ;
				padding: 0;
				border-radius: 0;
				background: transparent;
			}
		}
	}
	
</style>
